<?php

// Flag if this is an ARB transaction. Set to false by default.
$arb    = false;
// Store the posted values in an associative array
$fields = array();
foreach ($_REQUEST as $name => $value)
{
    // Create our associative array
    $fields[$name] = $value;
    // If we see a special field flag this as an ARB transaction
    if ($name == 'x_subscription_id')
    {
        $arb = true;
    }
}
// If it is an ARB transaction, do something with it
$status = $fields['x_response_code'];
$auth_code = $fields['x_auth_code'];
$id_transaction = $fields['x_trans_id'];
$id_invoice = $fields['x_invoice_num'];

$invoice = Doctrine_Core::getTable('Invoice')->find(array($id_invoice));
$invoice->setIdTransaction($id_transaction);
$invoice->setAuthCode($auth_code);

if ($status == "1") :
    $date = date('Y-m-d');
    $invoice->setIsPaid($status);
    $invoice->setPaymentDate($date);
endif;

$invoice->save();

?>

<?php if ($status == 1) : ?>
<table>
  <tbody>
    <tr>
      <th>Id invoice:</th>
      <td><?php echo $invoice->getIdInvoice() ?></td>
    </tr>
    <tr>
      <th>Authorization code:</th>
      <td><?php echo $auth_code; ?></td>
    </tr>
    <tr>
      <th>Transaction Id:</th>
      <td><?php echo $id_transaction; ?></td>
    </tr>
    <tr>
      <th>Invoice amount:</th>
      <td><?php echo $invoice->getInvoiceAmount() ?></td>
    </tr>
    <tr>
      <th>Shipping amount:</th>
      <td><?php echo $invoice->getShippingAmount() ?></td>
    </tr>
    <tr>
      <th>Tax amount:</th>
      <td><?php echo $invoice->getTaxAmount() ?></td>
    </tr>
    <tr>
      <th>Shipping name:</th>
      <td><?php echo $invoice->getShippingName() ?></td>
    </tr>
    <tr>
      <th>Shipping last name:</th>
      <td><?php echo $invoice->getShippingLastName() ?></td>
    </tr>
    <tr>
      <th>Shipping Company:</th>
      <td><?php echo $invoice->getShippingCompany() ?></td>
    </tr>
    <tr>
      <th>Shipping address:</th>
      <td><?php echo $invoice->getShippingAddress() ?></td>
    </tr>
    <tr>
      <th>Shipping state:</th>
      <td><?php echo $invoice->getShippingState() ?></td>
    </tr>
    <tr>
      <th>Shipping city:</th>
      <td><?php echo $invoice->getShippingCity() ?></td>
    </tr>
    <tr>
      <th>Shipping zip:</th>
      <td><?php echo $invoice->getShippingZip() ?></td>
    </tr>
    <tr>
      <th>Billing address:</th>
      <td><?php echo $invoice->getBillingAddress() ?></td>
    </tr>
    <tr>
      <th>Billing state:</th>
      <td><?php echo $invoice->getBillingState() ?></td>
    </tr>
    <tr>
      <th>Billing city:</th>
      <td><?php echo $invoice->getBillingCity() ?></td>
    </tr>
    <tr>
      <th>Billing zip:</th>
      <td><?php echo $invoice->getBillingZip() ?></td>
    </tr>
    <tr>
      <th>Billing phone:</th>
      <td><?php echo $invoice->getBillingPhone() ?></td>
    </tr>
    <tr>
      <th>Billing fax:</th>
      <td><?php echo $invoice->getBillingFax() ?></td>
    </tr>
    <tr>
      <th>Billing email:</th>
      <td><?php echo $invoice->getBillingEmail() ?></td>
    </tr>
    <tr>
      <th>Billing name:</th>
      <td><?php echo $invoice->getBillingName() ?></td>
    </tr>
    <tr>
      <th>Billing last name:</th>
      <td><?php echo $invoice->getBillingLastName() ?></td>
    </tr>
    <tr>
      <th>Billing company:</th>
      <td><?php echo $invoice->getBillingCompany() ?></td>
    </tr>
    <tr>
      <th>Created at:</th>
      <td><?php echo $invoice->getCreatedAt() ?></td>
    </tr>
  </tbody>
</table>
<?php else : ?>

Transaction failed

<?php endif; ?>
<a href="<?php echo url_for('@homepage'); ?>" >Go to Home</a>